// ==================================================================================
// Shared Genomics Project MPI Codebase
// Version 1.0 30/04/2010
//
// (c) 2010 University of Manchester all rights reserved
//
// This file is distributed under the GNU General Public License, Version 2.  
// Please see the file COPYING.txt for more details
// ==================================================================================

/*!
\file
\brief Implementation File Copying (windows.h dependency)
*/

#include <stdio.h>
#include <windows.h>

#include "copyfile.h"
#include "random_sleep.h"

// Windows specific code here, is easily replaceable with a standard linux version instead
// if we want to go cross platform on the MPI codes.
int copyAndDeleteFile(char *from, char *to) {
	if (from == NULL || to == NULL) return 0;
	else if (strlen(from) == 0 || strlen(to) == 0) return 0;

	if(CopyFileA(from, to, FALSE)) {
		if (SetFileAttributesA(to, FILE_ATTRIBUTE_NORMAL)) {
			if(DeleteFileA(from)) {
				random_sleep(50, 100);
				return 1;
			}
		}
	}
	
	return 0;
}

int copyFile(char *from, char *to) {
	if (from == NULL || to == NULL) return 0;
	else if (strlen(from) == 0 || strlen(to) == 0) return 0;
	
	if(CopyFileA(from, to, FALSE)) {
		if (SetFileAttributesA(to, FILE_ATTRIBUTE_NORMAL)) return 1;
	}
	
	return 0;
}

int deleteFile(char *path) {
	return DeleteFileA(path);
}
